package com.gnerv.battle.boot.module.base.controller;

import com.gnerv.battle.boot.module.base.model.dto.PermissionRoleDTO;
import com.gnerv.battle.boot.common.base.model.RestResult;
import com.gnerv.battle.boot.module.base.business.PermissionBusiness;
import com.gnerv.battle.boot.module.base.model.dto.PermissionCreateDTO;
import com.gnerv.battle.boot.module.base.model.dto.PermissionDTO;
import com.gnerv.battle.boot.module.base.model.dto.PermissionUpdateDTO;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author Gnerv LiGen
 */
@RestController
@AllArgsConstructor
@RequestMapping(value = "api/manage/permission")
public class PermissionController {

    private final PermissionBusiness permissionBusiness;

    @PostMapping(value = "")
    public RestResult<Void> create(@RequestBody PermissionCreateDTO permissionCreateDTO) {
        return permissionBusiness.create(permissionCreateDTO);
    }

    @PostMapping(value = "/role/bind")
    public RestResult<Void> bindRole(@RequestBody PermissionRoleDTO permissionRoleDTO) {
        return permissionBusiness.bindRole(permissionRoleDTO);
    }

    @DeleteMapping(value = "")
    public RestResult<Void> deleteByUkId(@RequestParam(value = "ukId") String ukId) {
        return permissionBusiness.deleteByUkId(ukId);
    }

    @PutMapping(value = "")
    public RestResult<Void> updateByUkId(@RequestBody PermissionUpdateDTO permissionUpdateDTO) {
        return permissionBusiness.updateByUkId(permissionUpdateDTO);
    }

    @GetMapping(value = "")
    public RestResult<PermissionDTO> selectByUkId(@RequestParam(value = "ukId") String ukId) {
        return permissionBusiness.selectByUkId(ukId);
    }

    @GetMapping(value = "list")
    public RestResult<List<PermissionDTO>> listByName(@RequestParam(required = false, value = "name") String name,
                                                      @RequestParam(required = false, value = "page") Integer page,
                                                      @RequestParam(required = false, value = "size") Integer size) {
        return permissionBusiness.listByName(name, page, size);
    }

    @GetMapping(value = "list/role")
    public RestResult<List<PermissionDTO>> listByRoleUkId(@RequestParam(value = "roleUkId") String roleUkId) {
        return permissionBusiness.listByRoleUkId(roleUkId);
    }

}
